package com.eling.elcms.cater.webapp.controller;

import com.eling.elcms.cater.model.DishType;
import com.eling.elcms.cater.service.IDishTypeService;
import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DishTypeController extends BaseFormController{
	@Autowired
	private IDishTypeService dishTypeService;
	
	@RequestMapping("/api/cater/dishtype/search*")
	@ResponseBody
	public List<DishType> sreach(@ModelAttribute SearchCondition sc,@ModelAttribute DishType dishType) {
		sc.setQueryCondition(dishType);
		return dishTypeService.search(sc); 
	}
	
	@RequestMapping("/api/cater/dishtype/query")
    @ResponseBody
    public List<DishType> query(@ModelAttribute DishType cond){
    	return dishTypeService.query(cond); 
    }
	
	@RequestMapping("/api/cater/dishtype/save")
    @ResponseBody
    public DishType save(@ModelAttribute@ModelFilling DishType dishType) {
		return dishTypeService.save(dishType);
    }
	
	@RequestMapping("/api/cater/dishtype/{pkDishType}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkDishType) {
		dishTypeService.remove(pkDishType);
	    return new Msg("删除成功");
	}

}
